//
//  tabview.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/5/1.
//

import SwiftUI

struct SlidingMenuView: View {
    @State private var selectedTab: Int = 0
    private let menuTitles = [LocalizedStringKey("Follow"),
                              LocalizedStringKey("Recommended"),
                              LocalizedStringKey("Lifestyle"),
                              LocalizedStringKey("Services"),
                              LocalizedStringKey("Food")]
    var body: some View {
        VStack{
            // 顶部菜单
                HStack {
                    ForEach(0..<menuTitles.count, id: \.self) { index in
                        Button(action: {
                            selectedTab = index
                        }) {
                            VStack {
                                Text(menuTitles[index])
                                    .font(.system(size: 16, weight: .medium))
                                    .foregroundColor(selectedTab == index ? AppColors.Brand6 : AppColors.Gy1)
                                    .frame(maxWidth: .infinity)
                                    .padding(.bottom, 8)
                                    .padding(.top, 11)
                                    Rectangle()
                                        .frame(height: 2)
                                        .foregroundColor(selectedTab == index ? AppColors.Brand6 : .clear)
                                        .padding(.horizontal, 18)
                              
                            }.frame(minWidth: 32)
                        }
                    }
                }
                .padding(.horizontal, 16)
     
            // 动态菜单内容
            TabView(selection: $selectedTab) {
                ForEach(0..<menuTitles.count, id: \.self) { index in
                    Text("\(menuTitles[index]) Content")
                        .frame(maxWidth: .infinity, maxHeight: .infinity)
                        .background(Color.gray.opacity(0.1))
                        .cornerRadius(12)
                        .padding()
                        .tag(index)
                }
            }
            .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
            .frame(maxWidth: .infinity)  // 确保 TabView 全屏
        }
        
    }
}

struct SlidingMenuView_Previews: PreviewProvider {
    static var previews: some View {
        SlidingMenuView()
    }
}
